import requests # 导入requests库，用于发送HTTP请求
import json # 导入json库，用于处理JSON数据
import base64
def encode_image(image_path):
  with open(image_path, "rb") as image_file:
    return base64.b64encode(image_file.read()).decode('utf-8')

# Path to your image
image_path = "32.jpg"

encoded_image = encode_image(image_path)

url = "https://api.siliconflow.cn/v1/chat/completions" # API请求的URL
headers = {
    "Content-Type": "application/json", # 设置请求头，内容类型为JSON
    "Authorization": "Bearer sk-vpvqufobomtnxirzaxnhettzkykozcvljcyoewtmqovjgeau" # 设置授权头，包含API密钥
}
data={
    "model": "THUDM/GLM-4.1V-9B-Thinking", # 指定使用的模型
    # "model": "Qwen/QwQ-32B",

    "messages": [ # 消息列表

        {
            "role": "user", # 角色为用户
              "content": [
                {"type": "text", "text": "你好，麻烦把图片里面的数据以python的字典格式返回给我"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/jpeg;base64,{encoded_image}" # Include the encoded image
                    }
                }
            ]
        }
    ],
    "max_tokens":250, # 设置最大生成的token数量
    "stream":False, # 设置是否以流式方式接收响应
    # "image": "32.jpg"
    
}
# resp= requests.post(url, headers=headers, data=json.dumps(data), files={'file': ('32.jpg', file_data, 'image/jpeg')}) # 发送POST请求
resp= requests.post(url, headers=headers, data=json.dumps(data))
print(resp.text) # 打印响应文本